#include "KByteRate.h"

void KByteRate::accumulate(size_t bytes)
{
    InterlockedExchangeAdd64(&m_bytes, bytes);
    InterlockedExchangeAdd64(&m_total, bytes);
}

double KByteRate::bytesPerSecond()
{
    LONGLONG bytes = InterlockedExchange64(&m_bytes, 0);
    double seconds = m_ticker.elapsed();
    m_ticker.reset();
    return bytes / seconds;
}

void KByteRate::reset()
{
    m_bytes = 0;
    m_total = 0;
    m_ticker.reset();
}

LONGLONG KByteRate::totalBytes()
{
    return InterlockedExchangeAdd64(&m_total, 0);
}